package com.cncbox.service.impl;

import com.cncbox.dao.ResourceDao;
import com.cncbox.entity.NoteResult;
import com.cncbox.entity.Resource;
import com.cncbox.service.ResourceService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author Develop_Peng
 * @version V1.0
 * @Package com.cncbox.service.impl
 * @Description: 资源服务实现类
 * @date 2016/3/31 13:35
 */
public class ResourceServiceImpl implements ResourceService {

    @Autowired
    private ResourceDao resourceDao;

    //    添加资源
    public NoteResult addResource(Resource resource) throws Exception {
        Boolean addBoolean = resourceDao.addResource(resource);
        NoteResult noteResult = new NoteResult();
        if (addBoolean) {
            noteResult.setStatus(1);
            noteResult.setMsg("ADD_SUCCESS");
        } else {
            noteResult.setStatus(0);
            noteResult.setMsg("ADD_ERROR");
        }
        return noteResult;
    }

    //查询资源
    public NoteResult queryResource(Integer quId) throws Exception {
        NoteResult noteResult = new NoteResult();
        Resource resource = resourceDao.queryResource(quId);
        if (resource != null) {
            noteResult.setStatus(1);
            noteResult.setMsg("QUERY_SUCCESS");
            noteResult.setData(resource);
        } else {
            noteResult.setStatus(0);
            noteResult.setMsg("QUERY_ERROR");
        }
        return noteResult;
    }

    //修改资源
    public NoteResult updateResource(Resource resource) throws Exception {
        NoteResult noteResult = new NoteResult();
        Boolean updateResult = resourceDao.updateResourcePathNameById(resource);
        if (updateResult) {
            noteResult.setStatus(1);
            noteResult.setMsg("UPDATE_SUCCESS");
        } else {
            noteResult.setStatus(0);
            noteResult.setMsg("UPDATE_ERROR");
        }
        return noteResult;
    }

    //删除资源
    public NoteResult removeResource(Integer resourceId) throws Exception {
        NoteResult noteResult = new NoteResult();
        Boolean deleteResourceById = resourceDao.deleteResourceById(resourceId);
        if(deleteResourceById){
            noteResult.setStatus(1);
            noteResult.setMsg("DELETE_SUCCESS");
        }else{
            noteResult.setStatus(0);
            noteResult.setMsg("DELETE_ERROR");
        }
        return noteResult;
    }


}
